package com.chaofan.websocket.Web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chaofan.websocket.entity.SysUser;
import com.chaofan.websocket.entity.WeixinUser;
import com.chaofan.websocket.mapper.SysUserMapper;
import com.chaofan.websocket.mapper.WeixinUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @program: websocket
 * @description:
 * @author: Mr.sun
 * @create: 2020-11-05 14:00
 **/
@Controller
@RequestMapping("/ws")
public class ViewController {

    @Autowired
    private WeixinUserMapper weixinUserMapper;

    @Autowired
    private SysUserMapper sysUserMapper;


    @RequestMapping("/getInitUser")
    public ModelAndView getInitUser(String room, String weixinId){
        ModelAndView modelAndView=new ModelAndView("redirect:/");
        QueryWrapper<WeixinUser> queryWrapperSdf = new QueryWrapper<>();
        queryWrapperSdf.lambda().eq(WeixinUser::getWexinId,weixinId).eq(WeixinUser::getRoom,room);
        WeixinUser weixinUser = weixinUserMapper.selectOne(queryWrapperSdf);
        QueryWrapper<SysUser> sysUserWrapper = new QueryWrapper<>();
        sysUserWrapper.lambda().eq(SysUser::getRoom,room);
        SysUser sysUser = sysUserMapper.selectOne(sysUserWrapper);
        if(weixinUser.getIsFlag()==0 && sysUser.getStatus().equals("0") && sysUser.getRoom()!=null){
            modelAndView.addObject("room",room);
            modelAndView.addObject("nick",weixinUser.getWexinName());
            modelAndView.addObject("weixinId",weixinId);
            modelAndView.addObject("image",weixinUser.getImage());
            return modelAndView;

        }else{
            ModelAndView result=new ModelAndView();
            return result;
        }
    }
}
